package com.xunkids.bos.migration.component.vo;


import org.springframework.http.HttpStatus;

/**
 * @author lihe
 */

public class Result<T> {

    private Integer code;
    private T data;
    private String msg;


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Result(Integer code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static <T> Result<T> ok() {
        return new Result<>(HttpStatus.OK.value(), null, null);
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(HttpStatus.OK.value(), data, null);
    }

    public static <T> Result<T> fail() {
        return new Result<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), null, null);
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), null, msg);
    }

    public static <T> Result<T> fail(HttpStatus status) {
        return new Result<>(status.value(), null, status.getReasonPhrase());
    }

    public static <T> Result<T> fail(Integer code, String msg) {
        return new Result<>(code, null, msg);
    }

    public static <T> Result<T> fail(HttpStatus status, String msg) {
        return new Result<>(status.value(), null, msg);
    }

    public static <T> Result<T> create(Integer code, T data, String msg) {
        return new Result<>(code, data, msg);
    }

    public static <T> Result<T> create(HttpStatus status, T data, String msg) {
        return new Result<>(status.value(), data, msg);
    }

    public static <T> Result<T> create(HttpStatus status) {
        return new Result<>(status.value(), null, status.getReasonPhrase());
    }

}
